package com.shenzhen.group.niuniu.card;

import com.shenzhen.group.common.card.Card;
import com.shenzhen.group.common.card.operation.CardCalculate;
import com.shenzhen.group.common.card.operation.CardOperation;
import com.shenzhen.group.common.entity.HandCardGroupBase;
import com.shenzhen.group.niuniu.operation.NiuniuCardCalculate;
import com.shenzhen.group.common.enumeration.CardCompareEnum;
import com.shenzhen.group.niuniu.result.NiuniuCardResult;
import lombok.Data;

/**
 * 牛牛手牌组
 * @author 周赛波
 * @version v1.0.0
 * @date 2021/9/20 13:55
 */
@Data
public class NiuniuHandCardGroup extends HandCardGroupBase implements CardCalculate {
    @Override
    public NiuniuCardResult calculateHandCardGroup() {
        NiuniuCardResult res = new NiuniuCardResult();
        res.setHandCardGroupBase(this);
        int[] num = new int[5];
        int n = 0;
        res.setMaxCard(cards.get(0));
        for (Card card : cards) {
            if (res.getMaxCard().compareTo(card) < 0) {
                res.setMaxCard(card);
            }
            num[n++] = Math.min(card.getValue(), 10);
        }
        int val = NiuniuCardCalculate.cardCalculate(num);
        res.setNiu(val);
        if (val > 7 && val < 10) {
            res.setMagnification(2);
        } else if (val == 10) {
            res.setMagnification(3);
        } else {
            res.setMagnification(1);
        }
        return res;
    }

    @Override
    public HandCardGroupBase sortCardByAsc(HandCardGroupBase cardGroup) {
        return null;
    }

    @Override
    public HandCardGroupBase sortCardByDesc(HandCardGroupBase cardGroup) {
        return null;
    }

    @Override
    public CardCompareEnum compareCard(HandCardGroupBase card1) {
        NiuniuCardResult cardResult1 = this.calculateHandCardGroup();
        NiuniuCardResult cardResult2 = ((NiuniuHandCardGroup) card1).calculateHandCardGroup();
        if (cardResult1.getNiu() > cardResult2.getNiu()) {
            return CardCompareEnum.WIN;
        } else if (cardResult1.getNiu() < cardResult2.getNiu()) {
            return CardCompareEnum.LOSE;
        } else {
            return cardResult1.getMaxCard().compareTo(cardResult2.getMaxCard()) > 0 ? CardCompareEnum.WIN : CardCompareEnum.LOSE;
        }
    }


}

